package com.example.fangyh09.fragment;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Activity4 extends AppCompatActivity implements MyFragment5.MyListener{
    EditText editText;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main4);
        editText = (EditText)findViewById(R.id.editText);
        button = (Button)findViewById(R.id.send);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = editText.getText().toString();
                MyFragment5 fragment5 = new MyFragment5();
                Bundle bundle = new Bundle();
                bundle.putString("name",text);
                fragment5.setArguments(bundle);
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction beginTranscation = fragmentManager.beginTransaction();
                beginTranscation.add(R.id.layout,fragment5,"fragment5");
                beginTranscation.commit();
                Toast.makeText(Activity4.this,"ok",Toast.LENGTH_SHORT).show();
            }

        });

    }

    @Override
    public void thank(String str) {
        Toast.makeText(Activity4.this, "receive " + str, Toast.LENGTH_SHORT).show();
    }
}
